
#include "Humans Select Building and Ship.asm"


Reset_Ship:

 ld (Player1 + Player_Unit), a
 RES Ship_Mode, (IY + flag + 2)
 SET Load_Ship_Sprite, (IY + flag + 1)
 SET Hot_Key_Ship_Menu_Pressed, (IY + flag + 2)
 B_CALL _Set_Ship_Mode


 SET MenuMode, (IY + Flag)
 
 ld hl, Edit_Ship_Group_Menu
 ld (Current_Menu), hl
 ld a, GroupOfShipsMenu
 ld (MenuIdentity), a 


 ret

#include "Humans Buy Ship and Research.asm"

Goto_Build_Research_Buildings:

 ld hl, Build_Research_Buildings
 ld (Current_Menu), hl
 SET MenuMode, (IY + Flag)
 SET Menu_Cursor_In_Center, (IY + flag)
 SET Wait_Between_Presses, (IY + flag)
 ld a, AdvancedStructuresMenu
 ld (MenuIdentity), a

 ret

Goto_Build_Basic_Buildings:

 ld hl, Build_Basic_Buildings
 ld (Current_Menu), hl
 SET MenuMode, (IY + Flag)
 SET Menu_Cursor_In_Center, (IY + flag)
 SET Wait_Between_Presses, (IY + flag)
 
 ld a, StructuresMenu
 ld (MenuIdentity), a

 ret


Get_Number_Of_Ships_On_Hold:

 ld hl, Player1 + Player_Unit
 ld a, (hl)
 ld hl, Player1 + Ship1
 call _Add_A_To_HL

 SET Load_Ship_Sprite, (IY + flag + 1)

 ret


Buy_Ship:

Add_Ship:


 call Get_Number_Of_Ships_On_Hold


 ld a, (hl)
 dec a
 cp 255
 jp z, Stay_On_Current_Button

 dec (hl)

 ld hl, Player1 + Current_Number_Of_Ships
 inc (hl)

 jp Stay_On_Current_Button

Remove_Ship:

 ld hl, Player1 + Current_Number_Of_Ships
 ld a, (hl)
 dec a
 cp 255
 jp z, Stay_On_Current_Button

 dec (hl)
 
 call Get_Number_Of_Ships_On_Hold

 inc (hl)

 jp Stay_On_Current_Button

Buy_Max:

 call Get_Number_Of_Ships_On_Hold
 ld a, (hl)
 ld (hl), 0

 ld hl, Player1 + Current_Number_Of_Ships
 ld (hl), a

  jp Stay_On_Current_Button


Ship_Group_Done:

 SET Ship_Mode, (IY + flag + 2)
 RES MenuMode, (IY + Flag)
 SET Menu_Cursor_In_Center, (IY + flag)



 ret


Stay_On_Current_Button:

 SET MenuMode, (IY + Flag)
 RES Menu_Cursor_In_Center, (IY + Flag) 
 ret


Add_Human_Processing_Unit:

 ;Current_Building points to the refinery we selected.
 ;We need to find out what building (out of 50) it is
 ;so that we can store information in the correct
 ;part of Structure_Tags.


 ;We don't want the menu to quit unless CLEAR is pressed

 SET MenuMode, (IY + Flag)
 SET Wait_Between_Presses, (IY + flag)


 call Get_To_Structure_Tags_From_Structure_Locations


 		

 ;HL contains the 1st byte of the correct refinery.
 ;In this case, Byte 1 is the number of processing
 ;units we want to have (some may still be constructing,
 ;but it's the number we WANT to have)
 ;and Byte 3 is the number of HP left before
 ;a processing unit is destroyed.  Byte 2 is the
 ;number of processing units we DO have.  Byte 4
 ;is used for a player who wants to que processing
 ;units up.
  
 ;First, make sure the refinery has no more than 20 processing units.
 
 ld a, (hl)
 
 cp 15

 jr c, _


 SET Draw_Standard_Alert_Box, (IY + flag + 2)
 


 ld hl, Too_Many_PUs

 B_CALL _Standard_Alert_Standard_Data

 ret




_
 
 push hl

 ld hl, (Player1 + Player_Money)

 ld de, 50

 or a
 sbc hl, de
 add hl, de

 pop bc

 jr nc, _

 SET Draw_Standard_Alert_Box, (IY + flag + 2)
 

 ld hl, Not_Enough_Crystals

 B_CALL _Standard_Alert_Standard_Data

 ret





_
 
 
 sbc hl, de
 ld (Player1 + Player_Money), hl

 ld h, b
 ld l, c

 ld a, (hl)	;Saved for later, when we check
		;if a processing unit is already being
		;built


 inc (hl)	;If the player has enough money,
		;a new processing unit will be added.



 ;We need to add a processing unit to the list of buildings
 ;under construction.  We can do this simply by
 ;copying the required information to the list.

 ;But first, we need to get the correct building location
 ;so that we can add HP to the right refinery

 ;First, we don't construct a new processing unit
 ;if one is being made already, so we see if one is being
 ;built already.

 inc hl

 cp (hl)
 
 ret nz
 
 ld hl, (Current_Building) ;Although we know the building
			   ;is a refinery, we need to
			   ;find out which refinery out
			   ;of many refineries it is.



 call Start_Construction_Of_Processing_Unit

 ret

Start_Construction_Of_Processing_Unit:

 or a
 ld de, Structure_Locations
 sbc hl, de			

 srl h \ rr l
 srl h \ rr l

 ld c, l	;Now register C contains the correct
		;refinery in the list of buildings
		;already on the map.

 ld hl, List_Of_Buildings_Under_Construction		
 ld a, (End_Of_List_Of_Buildings_Under_Construction)
 
 rla \ rla

 call _Add_A_To_HL

 ld (hl), c

 ex de, hl	;Place this location into DE
		;so that we can copy refinery data
 inc de 	

 ld hl, Processing_Unit_Construction
 ld bc, 3
 ldir
 
 ld hl, End_Of_List_Of_Buildings_Under_Construction
 inc (hl)

 ret



;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------

; BEGINNING MODIFIERS SHOULD NOT MESS WITH THE
; REST OF THE CODE IN THIS FILE

;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------

AddObjectToGameBegin:

 	SET Object_Ready_To_Add, (IY + flag)

 	SET Wait_Between_Presses, (IY + flag)
 	RES Cursor_Bitmap_Done, (IY + Flag)
	
	ld a, c
	ld (BuildingSelected), a
	B_CALL _Rotate_Cursor_Mode
	SET Menu_Mode, (IY + flag)
	ret


Draw_Item_Description: 




 push hl

 ld hl, InfoBox2
 ld de, plotsscreen
 ld bc, 12 * 15
 ldir


 ld hl, (Current_Menu)
 ld a, (hl)
 pop hl
 or a
 jr nz, _	;The text for soft key menus is not located in a specific
		;location.  We need to find it with special care

 ld de, 19	;Adding 19 to HL will place HL at the text data, meaning the
		;text that will be displayed depending on the menu item selected

 jr ++_
_

 ld a, (hl)

 add a, 16
 rrca \ rrca \ rrca \ rrca

 add a, a
 inc a

 ld d, 0
 ld e, a

_
 add hl, de

 call Get_X_Y_Icon_Menus ;Locate in the data the text needed to display

 add a, a	;Since each label for text is two bytes, we double the value in register
		;A to skip two bytes for each button the text pertains to

 ld d, 0
 ld e, a
 add hl, de	;HL now pertains to the location of the text we want to display.
		

 
 ld e, (hl)
 inc hl
 ld d, (hl) 
 

 ex de, hl	;HL no longer contains the location of the text.  It is now actually
		;pointed at the text.

 

 ld b,(hl)
 ld c, b	;The length of the first line of text.
 
		;We save this value because we need it later to determine if a 
		;second line of text needs to be displayed.
 

 inc hl		;HL goes past the length of the first line of next, and is now reading
		;the text itself.

 
 
 push hl	
 ld a, 2
 ld (penCol),a	;The text will be displayed at the top of the screen.

 ld (penRow),a
 push bc

 ;Copy our string so we can use the Font Routine from
 ;the first page with data that is on another page

 ld b, 0

 ld de, Text_Buffer

 ldir

 pop bc
 push bc

 ld hl, Text_Buffer
 
 

 B_CALL _Put_Text_B_Length


 pop bc
 ld hl, 8*256+2
 ld (penCol), hl
 pop hl


 ld b, 0
 add hl, bc	;Now hl points to the length of the second line of text, if there is
		;such a line.

 ld b, (hl)
 

 inc hl		;HL points to the second line of text.

 ;Copy our string so we can use the Font Routine from
 ;the first page with data that is on another page

 push bc
 
 ld c, b 
 ld b, 0

 ld de, Text_Buffer

 ldir

 pop bc


 ld hl, Text_Buffer
 
 B_CALL _Put_Text_B_Length


End_Draw_Item_Description:


 ret 

Get_X_Y_Icon_Menus: 

;Correctly locate where the text is.  It's located in the menu data,
			; so this sub will find the text.



 

 ld a, (TagX)

;Divide Register A by 16

 rra
 rra
 rra
 rra

 ld c, a
 push hl

 ld hl, (Current_Menu)
 ld a, (hl)

 pop hl
 or a
 jr z, _

 ld a, c

 ret

_

 ld e,c ; Saves the value

 ld a, (TagY)
 sub 17
 

 rra
 rra
 rra
 rra
 
 ld d,a
 

 add a, d
 add a, d
 add a, e


 
 ret









Draw_Ship_Group_Information:



 ld hl, InfoBox2
 ld de, plotsscreen
 ld bc, 12 * 15
 ldir


 ld hl, 2*256 + 2
 ld (penCol), hl

 ld hl, On_Hold_Text

 B_CALL _Put_Text_Zero_End


 ld hl, 2*256 + 36
 ld (penCol), hl

 ld hl, ZeroText2
 ld de, ASCIINumber
 ld bc, 6
 ldir

 ld a, (Player1 + Player_Unit)
 ld hl, Player1 + Ship1

 call _Add_A_To_HL
 
 ld d, 0
 ld e, (hl)

 b_call _bintobcd16

 
 ld hl, ASCIINumber

 B_CALL _Put_Text_Zero_End

 ld hl, ZeroText2
 ld de, ASCIINumber
 ld bc, 6
 ldir


 ld hl, 8 * 256 + 2
 ld (penCol), hl

 ld hl, In_Group_And_Max_Text
 B_CALL _Put_Text_Zero_End

 ld hl, 8 * 256 + 38
 ld (penCol), hl

 ld hl, ZeroText2
 ld de, ASCIINumber
 ld bc, 6
 ldir


 ld hl, Player1 + Current_Number_Of_Ships

 ld d, 0
 ld e, (hl)
 B_CALL _bintobcd16

 ld hl, ASCIINumber
 B_CALL _Put_Text_Zero_End

 ret



Get_To_Structure_Tags_From_Structure_Locations:

 ld hl, (Current_Building) 

 ld de, Structure_Tags - Structure_Locations
 
 add hl, de

 ret





InfoBox2:

.db %11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
.db %11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111,%11111111

Processing_Unit_Construction:

 .db 0, 120, $EE

ZeroText2:

.db 0, 0, 0, 0, 0, 0
